package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.web.anno.ResultController;
import com.lw.sbdemo2.entity.TkBasicDict;
import com.lw.sbdemo2.service.TkBasicDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

/**
 * <p>标题: 题库基础字典表服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-4-14
 */
@ResultController
@Api(description = "TkBasicDictController", tags = {"题库基础字典表服务"})
@RequestMapping(value = "/tkBasicDict")
public class TkBasicDictController extends BaseController {

    /**
     * 题库基础字典表服务
     */
    @Autowired
    private TkBasicDictService tkBasicDictService;
	
	@ApiOperation(value = "获取题库基础字典表列表")
    @GetMapping("")
    public List<TkBasicDict> findList(TkBasicDict tkBasicDict) {
        return tkBasicDictService.findList(tkBasicDict);
    }

    @ApiOperation(value = "获取题库基础字典表列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkBasicDict> page(String query, @Required("pageNum") PageInfo pageInfo, TkBasicDict tkBasicDict) {
        return tkBasicDictService.findListPage(query, pageInfo, tkBasicDict);
    }

    @ApiOperation(value = "获取题目类型题目细项", response = PageInfo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
        @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/findListTable")
    public List<TkBasicDict> findListTable(String query,  TkBasicDict tkBasicDict) {
        return tkBasicDictService.findListTable(query, tkBasicDict);
    }

    @ApiOperation(value = "获取题库基础字典表详细信息", notes = "根据url的id来获取题库基础字典表详细信息")
    @ApiImplicitParam(name = "id", value = "题库基础字典表ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkBasicDict get(@PathVariable String id) {
        return tkBasicDictService.getById(id);
    }

    @ApiOperation(value = "创建题库基础字典表")
    @PostMapping("/insert")
    public void insert(TkBasicDict tkBasicDict) {
		tkBasicDict.setCreatedTime(new Date());
//        tkBasicDict.setDictName(IdUtils.uuid());
        tkBasicDictService.insert(tkBasicDict);
    }

    @ApiOperation(value = "更新题库基础字典表详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "题库基础字典表ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkBasicDict tkBasicDict) {
		tkBasicDict.setModifiedTime(new Date());
        tkBasicDictService.update(tkBasicDict);
    }

    @ApiOperation(value = "删除题库基础字典表", notes = "删除题库基础字典表")
    @ApiImplicitParam(name = "id", value = "题库基础字典表ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkBasicDict(TkBasicDict tkBasicDict) {
        tkBasicDictService.delete(tkBasicDict);
    }
    
}